package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.shopCartService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/user/shoppingCart")
@Api(tags = "C端-购物车接口")
public class shopCartController {
    @Autowired
  private shopCartService shopCartService;




    @PostMapping("add")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shopCartService.save(shoppingCartDTO);
        return Result.success();
    }
    @GetMapping("list")
    public Result<List<ShoppingCart>> list(){
        return Result.success(shopCartService.getall());
    }


    @PostMapping("sub")
    public Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shopCartService.sub(shoppingCartDTO);
        return Result.success();
    }
    @DeleteMapping("clean")
    public Result clean(Long userId) {
        shopCartService.clean();
        return Result.success();
    }
}
